<template>
  <div class="router-wrap">
    <div class="router-item" v-for="(item,index) in routerArray" :key="index">
      <div class="left" v-html="vueGray" v-show="!item.select"></div>
      <div class="left" v-html="vue" v-show="item.select"></div>
      <div class="right" @click="jump(item)" >
        <div class="path-wrap" v-title>{{ getName(item.path)}}</div>
        <div class="name-wrap" v-title>{{ getName(item.name)}}</div>
      </div>
    </div>
  </div>
</template>
<script lang="ts" setup>
import vue from "@/assets/vue.svg?raw"
import vueGray from "@/assets/vueGray.svg?raw"
import  { UrlInfo ,routerApi} from "../hooks/routers"
import { mkApi } from "../utils/monkeyTool/monkeyApi"
// 自定义 v-title指令
const vTitle = {
  mounted(el: any){
    el.onmouseenter =(e:any) => { 
      const { clientWidth, scrollWidth, title } = el;
      if (!title && scrollWidth > clientWidth) el.title = el.innerText;
    } 
  },
}
const routerArray = routerApi.getRouterArrayInfo()
const jump = (urlInfo:UrlInfo):void =>{
  if(location.href.includes("localhost")){
    mkApi.URL_INFO.set(urlInfo)
    mkApi.SAAS_WEB_DEBUG_AVAILABLE.set(false)
    location.href = urlInfo.fulUrl
  }else{
    // 标准产品跳转
    location.href = urlInfo.fulUrl + location.search
  } 
}
function getName(url:string){
  if(!url || url === "/") return "/"
  if(url.startsWith("/")){
    return url.substring(1)
  }else{
    return url
  }
}

</script>
<style lang="less" scoped>
.router-wrap{
  width: 100%;
  padding: 4px;
  max-height: 200px;
  min-height: 20px;
  overflow-y: auto;
  overflow-x: hidden;
  cursor: pointer;
  .router-item{
    border-radius: 3px;
    padding:4px;
    align-items: center;
    justify-content: space-between;
    display: flex;
    transition:all .1s linear;
    .left{
      width: 25px;
      height: 25px;
      border-radius: 5px;
      background: #fff;
      display: flex;
      justify-content: center;
      align-items: center;
      padding: 2px;
      overflow: hidden;
      transition:padding .1s linear;
      &:hover{
        padding: 5px;
        transition:padding .1s linear;
      }
    }
    .right{
      flex: 1;
      display: flex;
      flex-flow: column;
      justify-content: space-between;
      margin-left: 4px; 
      height: 28px;
      overflow: hidden;
      white-space: nowrap;
      text-overflow:ellipsis;
      .path-wrap{
        line-height: 14px;
        display: block;
        font-size: 12px;
        color:#303133;
        overflow: hidden;
        white-space: nowrap;
        text-overflow:ellipsis;
      }
      .name-wrap{
        font-size: 12px;
        line-height: 12px;
        color: #c3c7cb;
      }
    }
    &:hover{
      transform: translateX(3px);
      background:#EBEDF0;
      box-shadow: 0 4px 8px 0 rgb(7 17 27 / 10%);
    }
  }
}
</style>